package com.utils;


import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Slf4j
public class GmdbCsvTranslate {

    public static void main(String[] args) throws Exception {
        String path="D:\\工作文档\\sinobase\\需求文档\\呼叫中心\\GMDB";
        String dbName="FRD";
        String dburl="jdbc:mysql://localhost:3228/FRD?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true";
        String dbUserName="root";
        String psd="Sinobase@123";
        Map<String, List<Map<String, Object>>> stringListMap = GmdbCsvDateUtils.importExcel(path);


        List<String> strings = MysqlDbUtil.showTables(dburl, dbUserName, psd);
        Map<String,String> tableNameMap=new HashMap<>();
        for (String string : strings) {
            tableNameMap.put(StringUtils.lowerCase(string),string);
        }
        stringListMap.entrySet().forEach(entry->{
            String tableName =StringUtils.lowerCase(entry.getKey().replace("_"," ").trim());
            if(tableNameMap.containsKey(tableName)) {
                List<Map<String, Object>> value = entry.getValue();
                MysqlDbUtil.bitchInsert(value,dburl, dbUserName, psd,tableNameMap.get(tableName));
            }else{
                log.info("文件 {} 未找到与之对应数据库",tableName);
            }
        });
    }
}
